package com.isdepci.project.factor.utils;

import com.isdepci.common.utils.StringUtils;
import com.isdepci.framework.security.service.PermissionService;
import com.isdepci.project.factor.domain.*;

import com.isdepci.project.factor.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Administrator
 */
@Component
public class FactorUtils {

    @Autowired
    private CategorizeInfoMapper categorizeInfoMapper;
    @Autowired
    private StandardStageMapper standardStageMapper;
    @Autowired
    private CarbonFactorInfoMapper carbonFactorInfoMapper;
    @Autowired
    private EnterpriseInfoMapper enterpriseInfoMapper;
    @Autowired
    private ProductCategorizeMapper productCategorizeMapper;

    public List<CarbonFactorInfo> selectCarbonFactorInfoList(){
        return carbonFactorInfoMapper.selectCarbonFactorInfoList(new CarbonFactorInfo(1));
    }

    /**
     * 获取因子分类缓存列表
     */
    public List<CategorizeInfo> selectCategorizeDictList() {
        List<CategorizeInfo> list = FactorRedisUtils.getCategorizeInfoCache();
        if (StringUtils.isNotNull(list)) {
            return list;
        }
        list = categorizeInfoMapper.selectCategorizeInfoList(new CategorizeInfo());
        if (StringUtils.isNotNull(list)) {
            FactorRedisUtils.setCategorizeInfoCache(list);
            return list;
        }
        return null;
    }

    /**
     * 获取项目标准阶段节点
     */
    public List<StandardStage> selectStandardStageDictList() {
        List<StandardStage> list = FactorRedisUtils.getStandardStageCache();
        if (StringUtils.isNotNull(list)) {
            return list;
        }
        list = standardStageMapper.selectStandardStageList(new StandardStage(1));
        if (StringUtils.isNotNull(list)) {
            FactorRedisUtils.setStandardStageCache(list);
            return list;
        }
        return null;
    }

    /**
     * 获取企业字典缓存
     */
    public List<EnterpriseInfo> selectEnterpriseInfoDict() {
        List<EnterpriseInfo> list = FactorRedisUtils.getEnterpriseInfoListCache();
        if (StringUtils.isNotNull(list)) {
            return list;
        }
        list = enterpriseInfoMapper.selectEnterpriseInfoList(new EnterpriseInfo());
        if (StringUtils.isNotNull(list)) {
            FactorRedisUtils.setEnterpriseInfoListCache(list);
            return list;
        }
        return null;
    }

    /**
     * 获取产品分类
     */
    public List<ProductCategorize> selectProductCategorizeDict() {
        List<ProductCategorize> list = FactorRedisUtils.getProductCategorizeCache();
        if (StringUtils.isNotNull(list)) {
            return list;
        }
        list = productCategorizeMapper.selectProductCategorizeList(new ProductCategorize());
        if (StringUtils.isNotNull(list)) {
            FactorRedisUtils.setProductCategorizeCache(list);
            return list;
        }
        return null;
    }
}
